﻿using Sys.Core;
using Sys.Core.Models.Dto;
using Sys.Core.Models.Queries;
using Sys.Core.Models.VO;
using Microsoft.AspNetCore.Mvc;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications.Web;
using MiniFox.Utility;
using MiniFox.Web.Filters;
using MiniFox.Web.Infrastructure;

namespace Sys.Controllers
{
    [NoCache, ValidationFilter, Area(GlobalConstants.AREA_NAME)]
    public class UserController : AuthorizedController<IUserService>
    {
        [HttpPost]
        public Response<ResultObject<IEnumerable<UserVo>>> Query([FromBody] PagedQueryObject<UserQuery> request)
        {
            var result = this.Component.Query(request);
            return result.CreateResponse();
        }

        [HttpGet]
        public Response<UserVo> Item([FromQuery] string id)
        {
            var result = this.Component.Item(id);
            return result.CreateResponse();
        }

        [HttpPost]
        public Response<UserVo> Create([FromBody] UserDto user)
        {
            var result = this.Component.Create(user);
            Response<UserVo> response = result.CreateResponse();

            return response;
        }

        [HttpPost]
        public Response<UserVo> Update([FromBody] UserDto user)
        {
            UserVo result = Component.Update(user);
            Response<UserVo> response = result.CreateResponse();
            return response;
        }

        [HttpGet]
        public Response InitPwd([FromQuery]string id)
        {
            Response response = new Response();
            this.Component.ResetPwd(id);
            return response;
        }

    }
}
